package io.char_stream;

import java.io.*;
import java.util.ArrayList;

/*
将一个文本文档
 */
public class Test_Reverse {
    public static void main(String[] args) throws IOException {
        //创建输入输出流对象
        BufferedReader br = new BufferedReader(new FileReader("wzx.txt"));

        //创建集合对象
        ArrayList<String> arrayList = new ArrayList<>();
        //将读到的数据存储在集合中
        String line;
        while ((line = br.readLine()) != null) {
            arrayList.add(line);
        }
        br.close();

        BufferedWriter bw = new BufferedWriter(new FileWriter("wzx_reverse.txt"));
        //倒着遍历集合将数据写到文件上
        for (int i = arrayList.size() - 1; i >= 0; i--) {
            bw.write(arrayList.get(i));
            bw.newLine();
        }
        bw.close();

        //注意流对象尽量晚开早关



        //extracted(fos);
    }

    private static void extracted(FileOutputStream fos) throws IOException {
        int num = 1000;
        while (num-- > 0) {
            fos.write("宝，今天我去输液了，什么夜？想你的夜\t".getBytes());
            if (num % 10 == 0) {
                fos.write(System.lineSeparator().getBytes());

            }
        }
    }
}
